//- Copyright (C) 2018-2022 Chatopera Inc, <https://www.chatopera.com>
//- 
//- Licensed under the Apache License, Version 2.0 (the "License");
//- you may not use this file except in compliance with the License.
//- You may obtain a copy of the License at
//- 
//-  http://www.apache.org/licenses/LICENSE-2.0
//- 
//-  Unless required by applicable law or agreed to in writing, software
//- distributed under the License is distributed on an "AS IS" BASIS,
//-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//- See the License for the specific language governing permissions and
//- limitations under the License.
if chatMessageList && chatMessageList.content
    for chatMessage in pugHelper.reverse(chatMessageList.content)
        if chatMessage.userid && chatMessage.userid == user.id
            .clearfix.chat-block
                .chat-right
                    img.user-img(src='/im/img/user.png', alt)
                    .chat-message
                        label.time= pugHelper.formatDate('yyyy-MM-dd HH:mm:ss', chatMessage.createtime)
                        label.user= user.uname
                    .chatting-right
                        i.arrow
                        .chat-content
                            if chatMessage.msgtype && chatMessage.msgtype == "image"
                                a(href="!{chatMessage.message}&original=true", target="_blank")
                                    img.ukefu-media-image(src="!{chatMessage.message}")
                            else if chatMessage.msgtype && chatMessage.msgtype == "file"
                                .ukefu-message-file
                                    .ukefu-file-icon
                                        img(src="/im/img/file.png")
                                    .ukefu-file-desc
                                        a(href="#{chatMessage.message}", target="_blank")
                                            div= chatMessage.filename
                                            div #{chatMessage.filesize / 1024}kb
                            else
                                | !{chatMessage.message}
        else
            .clearfix.chat-block
                .chat-left
                    img.user-img(src='/im/img/user.png', alt)
                    .chat-message
                        label.user= chatMessage.username
                        label.time= pugHelper.formatDate('yyyy-MM-dd HH:mm:ss', chatMessage.createtime)
                    .chatting-left
                        i.arrow
                        .chat-content
                            if chatMessage.msgtype && chatMessage.msgtype == "image"
                                a(href="!{chatMessage.message}&original=true", target="_blank")
                                    img.ukefu-media-image(src="!{chatMessage.message}")
                            else if chatMessage.msgtype && chatMessage.msgtype == "file"
                                .ukefu-message-file
                                    .ukefu-file-icon
                                        img(src="/im/img/file.png")
                                    .ukefu-file-desc
                                        a(href=chatMessage.message, target="_blank")
                                            div= chatMessage.filename
                                            div #{chatMessage.filesize / 1024}kb
                            else
                                | !{chatMessage.message}
